<?php

namespace App\Admin\Controllers;

use App\model\customer\CustomerRecords;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;
use PHPUnit\Util\Filter;

class FollowRecordController extends AdminController
{
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = '跟进记录';

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new CustomerRecords());

        $grid->column('id', __('Id'));
        $grid->column('customer.name', __('姓名'));
        $grid->column('customer.code', __('code'));
        $grid->column('customer.telephone', __('电话'));
        $grid->column('desc', __('跟进内容'));
        $grid->column('created_at', __('跟进时间'));
        $grid->disableActions();
        $grid->disableCreateButton();
        $grid->filter(function (Grid\Filter $filter){
            $filter->equal('customer.code','code');
            $filter->equal('customer.telephone','电话');
            $filter->equal('customer.name','姓名');

        });


        return $grid;
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     * @return Show
     */
    protected function detail($id)
    {
        $show = new Show(CustomerRecords::findOrFail($id));

        $show->field('id', __('Id'));
        $show->field('customer_id', __('Customer id'));
        $show->field('desc', __('Desc'));
        $show->field('created_at', __('Created at'));
        $show->field('updated_at', __('Updated at'));

        return $show;
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $form = new Form(new CustomerRecords());

        $form->number('customer_id', __('Customer id'));
        $form->text('desc', __('Desc'));

        return $form;
    }
}
